//
//  AboutViewController.m
//  FileLockerPro
//
//  Created by SDSL-3 on 7/9/12.
//  Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//

#import "AboutViewController.h"
#import "PreferenceManager.h"

@implementation AboutViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)didReceiveMemoryWarning
{
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Release any cached data, images, etc that aren't in use.
}

#pragma mark - View lifecycle

- (void)viewDidLoad
{
    [super viewDidLoad];
    txtInterval.text = [NSString stringWithFormat:@"%d", [PreferenceManager config_getInterval]];
    txtChance.text = [NSString stringWithFormat:@"%d", [PreferenceManager config_getChance]];
    txtLock.text = [NSString stringWithFormat:@"%d", [PreferenceManager config_getLock]];
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

-(BOOL)textFieldShouldReturn:(UITextField *)textField{
    [textField resignFirstResponder];
    return YES;
}

-(IBAction)btnSave_Click:(id)sender{
    [PreferenceManager config_setInterval:[txtInterval.text intValue]];
    [PreferenceManager config_setChance:[txtChance.text intValue]];
    [PreferenceManager config_setLock:[txtLock.text intValue]];
    
    if([pass0.text length] > 0 && [pass.text length] > 0){
        if([pass0.text isEqualToString:pass.text]){
            [PreferenceManager setPass:pass0.text];
            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"" message:@"Preferences and passcode updated" delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil];
            [alert show];
            [alert release];    
        }
        else{
            [PreferenceManager setPass:pass0.text];
            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"" message:@"Could not update passcode. Passcode cannot be empty and two entries must match for confirmation.\n (Preferences updated)" delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil];
            [alert show];
            [alert release];    
        }
        
        
    }
    else{
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"" message:@"Preferences updated (passcode not changed)" delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil];
        [alert show];
        [alert release];    
    }
    
    
    
    
    
}

-(IBAction)btnCancel_Click:(id)sender{
    [self.navigationController popViewControllerAnimated:YES];
}

@end
